package shake.jsf;

import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import shake.Event;
import shake.annotation.Component;
import shake.annotation.JSF;
import shake.event.JSFPhaseEvent;
import shake.servlet.ShakeServletContext;

import com.google.inject.Inject;

public class ShakeFacesPhaseListener implements PhaseListener {

	private static final long serialVersionUID = 1L;

	@JSF
	@Component
	static class PhaseIventInvoker {
		@Inject
		Event<JSFPhaseEvent.AFTER> after;
		@Inject
		Event<JSFPhaseEvent.BEFORE> before;
	}

	public void afterPhase(javax.faces.event.PhaseEvent event) {
		PhaseIventInvoker invoker = ShakeServletContext.getInjector()
				.getInstance(PhaseIventInvoker.class);
		invoker.after.fireEvent(event);
	}

	public void beforePhase(javax.faces.event.PhaseEvent event) {
		PhaseIventInvoker invoker = ShakeServletContext.getInjector()
				.getInstance(PhaseIventInvoker.class);
		invoker.before.fireEvent(event);
	}

	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}
}
